
package Persistencia;

import ArqvConfiguracao.HibernateUtil;
import Modelo.Balconista;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.classic.Session;

public class BalconistaDao {
    Session sessao = null;

    public void add(Balconista bal) {
        sessao = HibernateUtil.getSessionFactory().openSession();
        sessao.beginTransaction();
        sessao.save(bal);
        sessao.getTransaction().commit();
        sessao.close();
    }

    public Balconista getAluById(Long id) {
        sessao = HibernateUtil.getSessionFactory().openSession();
        sessao.beginTransaction();
        Balconista p = (Balconista) sessao.get(Balconista.class, id);
        sessao.getTransaction().commit();
        sessao.close();
        return p;
    }
    
    public void update (Balconista bal){
        sessao = HibernateUtil.getSessionFactory().openSession();
        sessao.beginTransaction();
        sessao.update(bal);
        sessao.getTransaction().commit();
        sessao.close();
    }

    public List<Balconista> list() {
        sessao = HibernateUtil.getSessionFactory().openSession();
        sessao.beginTransaction();
        List<Balconista> lista = new ArrayList<Balconista>();
        lista = sessao.createQuery("from Pessoa where DTYPE = 'Aluno'").list();
        sessao.getTransaction().commit();
        sessao.close();
        return lista;
    }
  

    public boolean remove(Balconista bal) {
        sessao = HibernateUtil.getSessionFactory().openSession();
        sessao.beginTransaction();
        sessao.delete(bal);
        sessao.getTransaction().commit();
        sessao.close();
        return true;
    }
}
